// pages/classify/classify.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    text: '通知:全场电视顺丰包邮，签收前务必开箱验收，如有问题及时客服咨询！',
    marqueePace: 0.5,//滚动速度
    marqueeDistance: 350,//初始滚动距离
    size: 14,
    orientation: 'left',//滚动方向
    interval: 20, // 时间间隔
    adUrl: '../image/31.png',
    category: [
      { name: '所有分类', id: 1 },
      { name: '43-50吋电视', id: 2 },
      { name: '55-65吋电视', id: 3 },
      { name: '冰箱', id: 4 },
      { name: '手机', id: 5 },
      { name: '洗衣机', id: 6 },
      { name: '生活电器', id: 7 },
      { name: 'K迷优品', id: 8 }
    ],
    detail: [],
    curIndex: 0, //下标
    toView: 1,   //category的id值
    categroyRight:[
      {id:1,name:"K24C 24吋 窄边高清节能护眼液晶平板电视",price:"¥599.00",img:'/img/1.jpg'},
      {id:2,name:"LED24E330C 24吋 高清窄边液晶平板电视",price:"¥666.00",img:'/img/2.jpg'},
      {id:3,name:"K32C 32吋高清LED USB蓝光",price:"¥699.00",img:'/img/3.jpg'},
      { id: 4, name: "K32 KKTV 32吋12核安卓智能WiFi 网络LED", price:"¥799.00",img:'https://www.konka.com/public/images/1a/86/41/58554fb5f5a0337ee811f4bceffb0ce4a3648f37.jpg?44475_OW800_OH800'},
      { id: 5, name: "LED32S1 八核安卓智能电视 无线WiFi", price:"¥849.00",img:'https://www.konka.com/public/images/5b/d9/b8/a97d9c48eb99d752b5813e8ab204a8f56e00f211.jpg?35413_OW800_OH800'},
      { id: 6, name: "K40C1 KKTV 39吋 蓝光高清窄边节能 USB2.0", price:"¥999.00",img:'https://www.konka.com/public/images/9e/b1/48/c3416503d0bd298716e6c77ac912387d535eedc0.jpg?29554_OW800_OH800'},
      { id: 7, name: "LED39E330C 39吋 高清窄边液晶平板电视", price:"¥1049.00",img:'https://www.konka.com/public/images/1a/f5/7b/7369a38c74931d77aa6ff437ff57ea517d16c732.jpg?24401_OW800_OH800'},
    ],
    categroyRightIndex:0,
    boolHidden: false, //控制点击添加符号显示隐藏内容
    animationData: {},
    transferParameters:0,
  },
  switchTab(e) {
    const that = this;
    this.setData({
      toView: e.target.dataset.id,//更新toView获取到的id值
      curIndex: e.target.dataset.index,//更新curIndex获取到的下标值
    })

    var toView = this.data.toView
    //没有用到显示隐藏--我不会---后续补充------------------------------------------------点这里收起来!!!!!!!!!!!!!!!!!
    switch (toView) {
      case 1:
        this.setData({
          categroyRight: [
            { id: 1, name: "K24C 24吋 窄边高清节能护眼液晶平板电视", price: "¥599.00", img: '/img/1.jpg' },
            { id: 2, name: "LED24E330C 24吋 高清窄边液晶平板电视", price: "¥666.00", img: '/img/2.jpg' },
            { id: 3, name: "K32C 32吋高清LED USB蓝光", price: "¥699.00", img: '/img/3.jpg' },
            { id: 4, name: "K32 KKTV 32吋12核安卓智能WiFi 网络LED", price: "¥799.00", img: 'https://www.konka.com/public/images/1a/86/41/58554fb5f5a0337ee811f4bceffb0ce4a3648f37.jpg?44475_OW800_OH800' },
            { id: 5, name: "LED32S1 八核安卓智能电视 无线WiFi", price: "¥849.00", img: 'https://www.konka.com/public/images/5b/d9/b8/a97d9c48eb99d752b5813e8ab204a8f56e00f211.jpg?35413_OW800_OH800' },
            { id: 6, name: "K40C1 KKTV 39吋 蓝光高清窄边节能 USB2.0", price: "¥999.00", img: 'https://www.konka.com/public/images/9e/b1/48/c3416503d0bd298716e6c77ac912387d535eedc0.jpg?29554_OW800_OH800' },
            { id: 7, name: "LED39E330C 39吋 高清窄边液晶平板电视", price: "¥1049.00", img: 'https://www.konka.com/public/images/1a/f5/7b/7369a38c74931d77aa6ff437ff57ea517d16c732.jpg?24401_OW800_OH800' },
          ],
        })
        break;
      case 2:
        this.setData({
          categroyRight: [
            { id: 1, name: "K24C 24吋 窄边高清节能护眼液晶平板电视", price: "¥599.00", img: '/img/1.jpg' },
            { id: 2, name: "LED24E330C 24吋 高清窄边液晶平板电视", price: "¥666.00", img: '/img/2.jpg' },
            { id: 7, name: "LED39E330C 39吋 高清窄边液晶平板电视", price: "¥1049.00", img: 'https://www.konka.com/public/images/1a/f5/7b/7369a38c74931d77aa6ff437ff57ea517d16c732.jpg?24401_OW800_OH800' },
            { id: 3, name: "K32C 32吋高清LED USB蓝光", price: "¥699.00", img: '/img/3.jpg' },
          ],
        })
        break;
      case 3:
        this.setData({
          categroyRight: [
            { id: 2, name: "LED24E330C 24吋 高清窄边液晶平板电视", price: "¥666.00", img: '/img/2.jpg' },
            { id: 3, name: "K32C 32吋高清LED USB蓝光", price: "¥699.00", img: '/img/3.jpg' },
            { id: 1, name: "K24C 24吋 窄边高清节能护眼液晶平板电视", price: "¥599.00", img: '/img/1.jpg' },
            { id: 5, name: "LED32S1 八核安卓智能电视 无线WiFi", price: "¥849.00", img: 'https://www.konka.com/public/images/5b/d9/b8/a97d9c48eb99d752b5813e8ab204a8f56e00f211.jpg?35413_OW800_OH800' },
          ],
        })
        break;
      case 4:
        this.setData({
          categroyRight: [
            { id: 5, name: "LED32S1 八核安卓智能电视 无线WiFi", price: "¥849.00", img: 'https://www.konka.com/public/images/5b/d9/b8/a97d9c48eb99d752b5813e8ab204a8f56e00f211.jpg?35413_OW800_OH800' },
            { id: 1, name: "K24C 24吋 窄边高清节能护眼液晶平板电视", price: "¥599.00", img: '/img/1.jpg' },
            { id: 2, name: "LED24E330C 24吋 高清窄边液晶平板电视", price: "¥666.00", img: '/img/2.jpg' },
            { id: 6, name: "K40C1 KKTV 39吋 蓝光高清窄边节能 USB2.0", price: "¥999.00", img: 'https://www.konka.com/public/images/9e/b1/48/c3416503d0bd298716e6c77ac912387d535eedc0.jpg?29554_OW800_OH800' },
          ],
        })
        break;
      case 5:
        this.setData({
          categroyRight: [
            { id: 2, name: "LED24E330C 24吋 高清窄边液晶平板电视", price: "¥666.00", img: '/img/2.jpg' },
            { id: 6, name: "K40C1 KKTV 39吋 蓝光高清窄边节能 USB2.0", price: "¥999.00", img: 'https://www.konka.com/public/images/9e/b1/48/c3416503d0bd298716e6c77ac912387d535eedc0.jpg?29554_OW800_OH800' },
            { id: 1, name: "K24C 24吋 窄边高清节能护眼液晶平板电视", price: "¥599.00", img: '/img/1.jpg' },
            { id: 7, name: "LED39E330C 39吋 高清窄边液晶平板电视", price: "¥1049.00", img: 'https://www.konka.com/public/images/1a/f5/7b/7369a38c74931d77aa6ff437ff57ea517d16c732.jpg?24401_OW800_OH800' },
            { id: 5, name: "LED32S1 八核安卓智能电视 无线WiFi", price: "¥849.00", img: 'https://www.konka.com/public/images/5b/d9/b8/a97d9c48eb99d752b5813e8ab204a8f56e00f211.jpg?35413_OW800_OH800' },
          ],
        })
        break;
      case 6:
        this.setData({
          categroyRight: [
            { id: 5, name: "LED32S1 八核安卓智能电视 无线WiFi", price: "¥849.00", img: 'https://www.konka.com/public/images/5b/d9/b8/a97d9c48eb99d752b5813e8ab204a8f56e00f211.jpg?35413_OW800_OH800' },
            { id: 1, name: "K24C 24吋 窄边高清节能护眼液晶平板电视", price: "¥599.00", img: '/img/1.jpg' },
            { id: 7, name: "LED39E330C 39吋 高清窄边液晶平板电视", price: "¥1049.00", img: 'https://www.konka.com/public/images/1a/f5/7b/7369a38c74931d77aa6ff437ff57ea517d16c732.jpg?24401_OW800_OH800' },
          ],
        })
        break;
      case 7:
        this.setData({
          categroyRight: [
            { id: 3, name: "K32C 32吋高清LED USB蓝光", price: "¥699.00", img: '/img/3.jpg' },
            { id: 5, name: "LED32S1 八核安卓智能电视 无线WiFi", price: "¥849.00", img: 'https://www.konka.com/public/images/5b/d9/b8/a97d9c48eb99d752b5813e8ab204a8f56e00f211.jpg?35413_OW800_OH800' },
            { id: 1, name: "K24C 24吋 窄边高清节能护眼液晶平板电视", price: "¥599.00", img: '/img/1.jpg' },
            { id: 7, name: "LED39E330C 39吋 高清窄边液晶平板电视", price: "¥1049.00", img: 'https://www.konka.com/public/images/1a/f5/7b/7369a38c74931d77aa6ff437ff57ea517d16c732.jpg?24401_OW800_OH800' },
          ],
        })
        break;
      case 8:
        this.setData({
          categroyRight: [
            { id: 7, name: "LED39E330C 39吋 高清窄边液晶平板电视", price: "¥1049.00", img: 'https://www.konka.com/public/images/1a/f5/7b/7369a38c74931d77aa6ff437ff57ea517d16c732.jpg?24401_OW800_OH800' },
            { id: 6, name: "K40C1 KKTV 39吋 蓝光高清窄边节能 USB2.0", price: "¥999.00", img: 'https://www.konka.com/public/images/9e/b1/48/c3416503d0bd298716e6c77ac912387d535eedc0.jpg?29554_OW800_OH800' },
            { id: 5, name: "LED32S1 八核安卓智能电视 无线WiFi", price: "¥849.00", img: 'https://www.konka.com/public/images/5b/d9/b8/a97d9c48eb99d752b5813e8ab204a8f56e00f211.jpg?35413_OW800_OH800' },
          ],
        })
        break;
    }



    console.log("我是id值toView:",e.target.dataset.id)
    console.log("我是下标值curIndex:",e.target.dataset.index)
  },
  right(e){
    const that = this;
    var toView = this.data.toView
    console.log("我是第" + toView + "类,id为" + e.currentTarget.dataset.id+"的商品")
    //先关闭下面的购物信息
    var animation = wx.createAnimation({
      duration: 300,
      timingFunction: 'linear'
    })
    that.animation = animation
    animation.translateY(300).step()
    that.setData({
      animationData: animation.export()
    });
  },
  rightShopping(e){
    //先关闭下面的购物信息
    var that = this;
    var animation = wx.createAnimation({
      duration: 300,
      timingFunction: 'linear'
    })
    that.animation = animation
    animation.translateY(300).step()
    that.setData({
      animationData: animation.export()
    });
    console.log("我是查看商品")
  },
  // 打开购物车
  openCar: function (e) {
    // 用that取代this，防止不必要的情况发生
    var that = this;
    // 创建一个动画实例
    var animation = wx.createAnimation({
      // 动画持续时间
      duration: 300,
      // 定义动画效果，当前是匀速
      timingFunction: 'linear'
    })
    // 将该变量赋值给当前动画
    that.animation = animation
    // 先在y轴偏移，然后用step()完成一个动画
    animation.translateY(300).step()
    // 用setData改变当前动画
    that.setData({
      // 通过export()方法导出数据
      animationData: animation.export(),
      // 改变view里面的Wx：if
      boolHidden: true
    })
    // 设置setTimeout来改变y轴偏移量，实现有感觉的滑动
    setTimeout(function () {
      animation.translateY(0).step()
      that.setData({
        animationData: animation.export()
      })
    }, 200)

    //添加按钮传参到下弹出框
    //先判断这个商品是第几类的第几个商品
    var toView = this.data.toView;
    var whatSizeSpring = e.currentTarget.dataset.id;
    console.log("成功获取到第" + toView + "类第" + whatSizeSpring + "号商品")
    
    
    //更新商品到弹出框
  },
  // 关闭购物车
  closeHide: function (e) {
    var that = this;
    var animation = wx.createAnimation({
      duration: 300,
      timingFunction: 'linear'
    })
    that.animation = animation
    animation.translateY(300).step()
    that.setData({
      animationData: animation.export()
    });
  },
  //点击其他地方也能关闭下面的购物信息    这里可以使用蒙版---------------------------------
  categroy(){
    var that = this;
    var animation = wx.createAnimation({
      duration: 300,
      timingFunction: 'linear'
    })
    that.animation = animation
    animation.translateY(300).step()
    that.setData({
      animationData: animation.export()
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 页面显示
    var that = this;
    var length = that.data.text.length * that.data.size;//文字长度
    var windowWidth = wx.getSystemInfoSync().windowWidth;// 屏幕宽度
    that.setData({
      length: length,
      windowWidth: windowWidth,
    });
    that.runMarquee();// 水平一行字滚动完了再按照原来的方向滚动
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  runMarquee: function () {
    var that = this;
    var interval = setInterval(function () {
      //文字一直移动到末端
      if (-that.data.marqueeDistance < that.data.length) {
        that.setData({
          marqueeDistance: that.data.marqueeDistance - that.data.marqueePace,
        });
      } else {
        clearInterval(interval);
        that.setData({
          marqueeDistance: that.data.windowWidth
        });
        that.runMarquee();
      }
    }, that.data.interval);
  }
})